
// 82.删除排序链表中的重复元素II
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* phead = new ListNode , *tail = phead; 
        phead->next = head;
        ListNode *cur = head;
        while(cur)
        {
            ListNode *start = cur;
            while(cur && start->val == cur->val) cur = cur->next;
            if(start -> next == cur)    // 不是重复的
                tail = tail->next;
            else                        // 删除[satrt , cur)之间的节点
                tail -> next = cur;
        }
        return phead->next;
    }
};